{include file="base/_meta" /}
</head>
<body>

<!-- 正文开始 -->
<div class="layui-fluid layui-form">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row">

                <input type="hidden" name="id" value="{$data.id|default=''}">

                <div class="layui-col-sm6">

                    <div class="layui-form-item">
                        <label class="layui-form-label">所属分类:</label>
                        <div class="layui-input-block">
                            <div id="cate" class="xm-select-cate"></div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label layui-form-required">名称:</label>
                        <div class="layui-input-block">
                            <input name="title" placeholder="请输入名称" class="layui-input"
                                   lay-verType="tips" lay-verify="required" required autocomplete="off" value="{$data.title|default=''}"/>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">排序:</label>
                        <div class="layui-input-block">
                            <input name="sort" placeholder="请输入名称" class="layui-input" required autocomplete="off" type="number" value="{$data.sort|default='0'}"/>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">状态:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="show" value="10" title="显示" {neq name="$data.show" value="20"}checked{/neq}>
                            <input type="radio" name="show" value="20" title="隐藏" {eq name="$data.show" value="20"}checked{/eq}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">置顶:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="top" value="10" title="置顶" {neq name="$data.top" value="20"}checked{/neq}>
                            <input type="radio" name="top" value="20" title="不置顶" {eq name="$data.top" value="20"}checked{/eq}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">简介:</label>
                        <div class="layui-input-block">
                            <textarea name="desc" placeholder="请输入" class="layui-textarea">{$data.desc|default=''}</textarea>
                        </div>
                    </div>

                </div>

                <div class="layui-col-sm6">

                    <div class="layui-form-item">
                        <label class="layui-form-label">缩略图:</label>
                        <div class="layui-input-block">
                            <div class="layui-upload-drag" id="site_logo" onclick="upload_file('site_logo',1)">
                                <i class="layui-icon"></i>
                                <p>点击上传，或将文件拖拽到此处</p>
                                <div>
                                    <hr>
                                    <img src="{$data.img_thumb|default='/static/images/default_img.png'}" alt="上传成功后渲染" style="max-width: 196px">
                                    <input type="hidden" name="img_thumb" value="{$data.img_thumb|default=''}">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-col-sm12">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">内容:</label>
                        <div class="layui-input-block">
                            <script id="container" name="content" type="text/plain">{:html_entity_decode($data.content)}</script>
                        </div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <button class="layui-btn" lay-filter="authoritiesEditSubmit" lay-submit>保存</button>
                </div>

            </div>
        </div>
    </div>
</div>

<!-- js部分 -->
{include file="base/_script" /}
<!-- 配置文件 -->
<script type="text/javascript" src="__LIB__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__LIB__/ueditor/ueditor.all.js"></script>
<script>
    layui.use(['layer', 'form', 'admin','xmSelect'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xmSelect = layui.xmSelect;

        var ue = UE.getEditor('container',{
            initialFrameHeight:500,
            wordCount:false,
        });

        $.post("{:url('article/article_cate_tree')}",function (ret) {
            var cateXmSelect = xmSelect.render({
                el: '#cate',
                height: '250px',
                name:"article_cate_id",
                data: ret.data,
                initValue: {$data.cate_id|default="[]"},
                model: {
                    label: {type: 'text'},
                },
                prop: {
                    name: 'name',
                    value: 'id'
                },
                tree: {
                    show: true,
                    indent: 15,
                    strict: true,
                    expandedKeys: true
                }
            })
        })

        /* 监听表单提交 */
        form.on('submit(authoritiesEditSubmit)', function (data) {
            data.field.content = ue.getContent();
            $.get("{:url('article/article_save')}", data.field, function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg, {icon: 1,time:1000},function () {
                        admin.closeThisTabs()
                    });
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });
    });
</script>
</body>
</html>
